from api.handler.ce.AbstractBatchCE import AbstractBatchCE
from api.model.BatchOutputPipe import BatchOutputPipe
from api.model.FdInputPipe import FdInputPipe
from munch import Munch
import json
# from config.annotation import Value

class DangerLevelHandler(AbstractBatchCE):
    """师资力量资产 院士，教授，博导 研导人数 """
    def do_compute(self, output_stream: BatchOutputPipe, source_fds: FdInputPipe, params: dict):
        # 院士，教授
        pro_fd = source_fds.get_fd('VIEW_GJB_DATA_112')
        pro_sql = """
        select (ZGGCYYS + ZGKXYYS) as academician_num, (ZJXZJLJHJZJS + ZJXZJLJHTPJS) as professor_num, FILLUPYEAR as fill_year
from VIEW_GJB_DATA_112
WHERE FILLUPYEAR = 2020 and ID LIKE 'B%'
        """
        pro_results = pro_fd.query(pro_sql)

        guid_pro_fd = source_fds.get_fd('VIEW_GJB_DATA_451')
        guid_pro_sql = """
        SELECT L1 as doctor_guid
FROM `VIEW_GJB_DATA_451`
WHERE FILLUPYEAR=2020 and FF2=6 and ID LIKE 'b%'
        """
        guid_pro_results = guid_pro_fd.query(guid_pro_sql)

        guid_graduate_fd = source_fds.get_fd('VIEW_GJB_DATA_451')
        guid_graduate_sql = """
        SELECT L1 as graduate_guid
FROM `VIEW_GJB_DATA_451`
WHERE FILLUPYEAR=2020 and FF2=8 and ID LIKE 'b%'
        """
        guid_graduate_results = guid_graduate_fd.query(guid_graduate_sql)

        data = Munch()
        data.fill_year = pro_results[0].fill_year
        data.academician_num = pro_results[0].academician_num
        data.professor_num = pro_results[0].professor_num
        data.doctor_guid = guid_pro_results[0].doctor_guid
        data.graduate_guid = guid_graduate_results[0].graduate_guid
        output_stream.output_for_upsert(data)



